<template>
  <Dialog v-model="dialogVisible" :max-height="570" :scroll="true" title="详情" width="800">
    <el-descriptions :column="1" :label-width="130" border>
      <el-descriptions-item label="日志编号">
        {{ detailData.smsLogId }}
      </el-descriptions-item>
      <el-descriptions-item label="短信渠道">
        {{ detailData.channelSignature }}
        <dict-tag :options="system_sms_channel_type" :value="detailData.channelCode" />
      </el-descriptions-item>
      <el-descriptions-item label="短信模板">
        {{ detailData.templateName }} / {{ detailData.templateCode }}
        <dict-tag :options="system_sms_business_type" :value="detailData.templateType" />
      </el-descriptions-item>
      <el-descriptions-item label="渠道模板编号">
        {{ detailData.apiTemplateId }}
      </el-descriptions-item>
      <el-descriptions-item label="用户信息">
        {{ detailData.mobile }}
        <dict-tag
          v-if="detailData.userType"
          :options="common_user_type"
          :value="detailData.userType"
        />
        <span v-if="detailData.userId">（{{ detailData.userId }}）</span>
      </el-descriptions-item>
      <el-descriptions-item label="短信内容">
        {{ detailData.smsContent }}
      </el-descriptions-item>
      <el-descriptions-item label="短信参数">
        {{ detailData.templateParams }}
      </el-descriptions-item>
      <el-descriptions-item label="提交时间">
        {{ detailData.createTime }}
      </el-descriptions-item>
      <el-descriptions-item label="发送状态">
        <dict-tag :options="system_sms_send_status" :value="detailData.sendStatus" />
        {{ detailData.sendTime }}
      </el-descriptions-item>
      <el-descriptions-item label="渠道发送结果">
        <span v-if="detailData.apiSendCode"
          >{{ detailData.apiSendCode }} / {{ detailData.apiSendMsg }}</span
        >
      </el-descriptions-item>
      <el-descriptions-item label="渠道短信编号">
        {{ detailData.apiSerialNo }}
      </el-descriptions-item>
      <el-descriptions-item label="渠道请求编号">
        {{ detailData.apiRequestId }}
      </el-descriptions-item>
      <el-descriptions-item label="接收状态">
        <dict-tag :options="system_sms_receive_status" :value="detailData.receiveStatus" />
        {{ detailData.receiveTime }}
      </el-descriptions-item>
      <el-descriptions-item label="渠道接收结果">
        <span v-if="detailData.apiReceiveCode"
          >{{ detailData.apiReceiveCode }} / {{ detailData.apiReceiveMsg }}</span
        >
      </el-descriptions-item>
    </el-descriptions>
  </Dialog>
</template>

<script setup lang="ts">
import { SmsLogVO } from '@/api/system/sms/sms_log'
import { DICT_TYPE } from '@/utils/dict'

defineOptions({ name: 'SystemSmsLogDetail' })

const { system_sms_business_type, system_sms_channel_type, common_user_type } = useDict(
  DICT_TYPE.system_sms_business_type,
  DICT_TYPE.system_sms_channel_type,
  DICT_TYPE.common_user_type
)
const { system_sms_send_status, system_sms_receive_status } = useIntDict(
  DICT_TYPE.system_sms_send_status,
  DICT_TYPE.system_sms_receive_status
)

const dialogVisible = ref(false) // 弹窗的是否展示
const detailData = ref() // 详情数据

/** 打开弹窗 */
const open = async (data: SmsLogVO) => {
  dialogVisible.value = true
  detailData.value = data
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>

<style scoped lang="scss"></style>
